package com.example.rabbitmq.direct.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;

/**
 * @Auther:
 * @Description:
 * @Date: 2019/12/26 17:45
 */
//@Configuration
public class DirectRabbitMQConfig {
    /**
     * direct exchange(直连型交换机)
     * 一对一 发送、接受 消息
     *
     * @return
     */

    // 声明队列
    @Bean
    public Queue sendQueue() {
        return new Queue("myDirectQueue", true);//true 是否持久
    }

    @Bean
    public Queue myDirectQueueResponse() {
        return new Queue("myDirectQueueResponse", true);
    }

    //声明交换机
    @Bean
    public DirectExchange myDirectExchange() {
        return new DirectExchange("myDirectExchange");
    }

    //绑定，将队列和交换机绑定，并设置用于匹配键: myDirectRoutingKey
    @Bean
    public Binding bindDirect() {
        return BindingBuilder.bind(sendQueue()).to(myDirectExchange()).with("myDirectRoutingKey");
    }

    // 绑定 队列和交换机，指定匹配键，myDirectRoutingKey
    @Bean
    public Binding bindingDirectResponse() {
        return BindingBuilder.bind(myDirectQueueResponse()).to(myDirectExchange()).with("myDirectRoutingKeyResponse");
    }

}

